package com.contain.stack;

import java.util.LinkedList;

public class MyStack<T> {

	private LinkedList<T> storage = new LinkedList<T>();

	// 入栈
	public void push(T t) {
		storage.addFirst(t);
	}

	// 返回栈顶元素
	public T peek() {
		return storage.getFirst();
	}

	// 栈顶元素出栈，并返回该元素
	public T pop() {
		return storage.removeFirst();
	}

	public boolean empty() {
		return storage.isEmpty();
	}

	public String toString() {
		return storage.toString();
	}

	public static void main(String[] args) {
		MyStack<String> stack = new MyStack<String>();
		for (String string : "my name is zhang su lei".split(" ")) {
			stack.push(string);
		}
		System.out.println(stack);

		while (!stack.empty()) {
			System.out.println(stack.pop());
		}
	}

}
